package com.flamingo.xiaomiweather.ui.place;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Transformations;
import androidx.lifecycle.ViewModel;

import com.flamingo.xiaomiweather.common.Result;
import com.flamingo.xiaomiweather.logic.Repository;
import com.flamingo.xiaomiweather.logic.model.PlaceResponse;


public class PlaceViewModel extends ViewModel {
    private final MutableLiveData<String> searchLiveData = new MutableLiveData<>();
    private PlaceResponse placeResponse;


    public void setPlaceResponse(PlaceResponse placeResponse) {
        this.placeResponse = placeResponse;
    }

    public PlaceResponse getPlaceResponse() {
        return placeResponse;
    }


    public final LiveData<Result<PlaceResponse>> placeLiveData = Transformations.switchMap(searchLiveData, query ->
            new Repository().searchPlaces(query)
    );

    public void searchPlaces(String query) {
        searchLiveData.setValue(query);
    }

}
